﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Controls
{
    public partial class Comment : System.Web.UI.UserControl
    {
        ViewDetail viewdetails = new ViewDetail();
        int msp = 0;
        public string nameproduct;
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = DAL.DCollector.DBCollector.Instance.SelectSQL("Select * from tbl_Product Where Product_ID = " + ProductDetail.id + "");
            nameproduct = dt.Rows[0]["Product_Name"].ToString();
            ltr_comment.Text += BOL.Comment.Instance.getCommnet1("tbl_Comment1", ProductDetail.id, "*");
        }

        protected void btn_Comment1_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Bank", "Bank_ID"));
            string commentname = txtCommentName.Text;
            string commentemail = txtCommentEmail.Text;
            string commentdetails = txtDetails1.Text;
            DateTime datecomment = DateTime.Now;
            if (nextid == 0)
            {
                string value = "1," + ProductDetail.id + ",N'" + commentname + "','" + commentemail + "',N'" + commentdetails + "',0,'" + datecomment + "',1,'/Images/Image-User/default.jpg'";
                List<string> values = new List<string>();
                values.Add(value);
                DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Comment1", "insertemployee", values, false);
                Response.Redirect(Request.Url.ToString());
            }
            else
            {
                int idnextcomment = nextid + 1;
                string value = "" + idnextcomment + "," + ProductDetail.id + ",N'" + commentname + "','" + commentemail + "',N'" + commentdetails + "',0,'" + datecomment + "',1,'/Images/Image-User/default.jpg'";
                List<string> values = new List<string>();
                values.Add(value);
                DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Comment1", "insertemployee", values, false);
                Response.Redirect(Request.Url.ToString());
            }

        }

        protected void btn_Comment2_Click(object sender, EventArgs e)
        {

            string commentname = Session["Username"].ToString();
            string commentemail = Session["Employee_Email"].ToString();
            string commentdetails = txtDetails2.Text;
            DateTime datecomment = DateTime.Now;
            string avatar = Session["Employee_Avatar"].ToString();
            string value = "" + ProductDetail.id + ",N'" + commentname + "','" + commentemail + "',N'" + commentdetails + "',0,'" + datecomment + "',1,'" + avatar + "'";
            List<string> values = new List<string>();
            values.Add(value);
            DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Comment1", "insertemployee", values, false);
            Response.Redirect(Request.Url.ToString());
        }
    }
}